#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 5e5 + 10;

int largestRectangleArea(vector<int>& heights) {
    int n = heights.size();
    vector<int> a(n + 5, 0);
    for (int i = 1; i <= n; i++) a[i] = heights[i - 1];

    stack<int> stk;
    int res = 0;
    stk.push(0);

    for (int i = 1; i <= n + 1; i++) {
        while (stk.top() != 0 && a[stk.top()] > a[i]) {
            int h = a[stk.top()]; // 栈顶对应的高度是h
            stk.pop();

            int l = stk.top(); 
            // 右端点为i-1, 因为a[i]小于h了,所以最右边管到i-1
            // 左端点为l+1, 因为a[l]也小于h了, 单调栈性质, l+1肯定大于h
            res = max(res, h * (i-l-1));
        }
        stk.push(i);
    }

    return res;
}

int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    int n;
    vector<int> heights;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        heights.push_back(x);
    }
    cout << largestRectangleArea(heights) << endl;
    return 0;
}